package org.testis.services;

import org.testis.data.TestStepDataObject;
import org.testis.data.TestStepException;
import org.testis.logging.AtofLogLevel;
import org.testis.logging.LogSenderService;


/**
 * Base class of a module provider service. 
 * Modules must extend this class.
 * Any special action for module can be handled over a service. 
 * @author nurhat
 */
public abstract class AtofModuleService
{

    protected TestStepDataObject m_dataObj;


    public TestStepDataObject getDataObj()
    {
        return m_dataObj;
    }


    public void setDataObj(TestStepDataObject m_dataObj)
    {
        this.m_dataObj = m_dataObj;
    }


    public final boolean runTest()
    {
        String className = super.getClass().getSimpleName();
        try {
            AtofModuleActionFactoryCreator factoryCreator =
                new AtofModuleActionFactoryCreator();

            AtofModuleActionFactory factory = factoryCreator.getInstance(
                getDataObj().getModuleType());
            AtofModuleAction actionObj =
                factory.getActionObject(getDataObj().getActionType());
            return actionObj.processRequest(this);
        } catch (TestStepException ex) {
            LogSenderService.putMessageOnQueue(
                className,
                AtofLogLevel.ERROR,
                "Test step failed...Error:" + ex.toString(),
                getDataObj().getMessageId());
            throw ex;
        } catch (Exception ex) {
            LogSenderService.putMessageOnQueue(
                className,
                AtofLogLevel.ERROR,
                "Test step failed...Error:" +ex.toString(),
                getDataObj().getMessageId());
        }


        return false;
    }
}
